<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta charset="UTF-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand" />
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
<title>教师首页-精准微课堂</title>
<%@ include file="/common/commonLib.jsp"%>
<link rel="stylesheet" type="text/css" href="<c:url value='/css/teacher-index.css'/>" />
<link rel="stylesheet" type="text/css" href="<c:url value='/css/common-main.css'/>"/>
<link rel=stylesheet href="http://cdn.bootcss.com/font-awesome/4.3.0/css/font-awesome.min.css">
<script src="<c:url value='/js/teacher-index.js'/>" type="text/javascript" charset="utf-8"></script>

</head>
<body>
	<div class="header">
		<%@include file="/common/header.jsp"%>
	</div>
	<div class="main" >
		<div class="container-fluid teacher-course-box">
			<div class="content-box">
				<div class="row">
					<div class="col-md-12 teachIndex-content">
						<div class="teachIndex-content-top">
							<div class="row">
								<div class="col-md-2"></div>
								<div class="col-md-6 content-top-title"  style="font-size: 2rem;">
									
									<shiro:hasRole name="teacher">
										<h3 id="todayLesson" style="color: #f90c0c;">今日课堂</h3>
										<h3 id="myCourse">我的课程</h3>
									</shiro:hasRole>
									<shiro:hasRole name="assistant">
										<h3 id="todayAssiLesson" style="color: #f90c0c;">今日课堂</h3>
										<h3 id="AssiCourse">我的课程</h3>
									</shiro:hasRole>
								</div>
								<div class="col-md-4 index-newCourse">
									<shiro:hasRole name="teacher">
										<button type="button" class="btn btn-primary" id="new-course" style="box-shadow: 2px 2px 4px 0px #0f71d6;">新建课程</button>
									</shiro:hasRole>
								</div>
								
							</div>
						</div>
						<div class="row">
							<div class="col-md-1"></div>
							<div class="col-md-10">
								<div class="index-con">
									<div class="row">
										<div class="col-md-1"></div>
										<div class="col-md-10">
											<!-- 我的课程 -->
											<div id="my-course-container" style="display:none;">
												<div class="col-md-12">
													<div id="container"></div>
												</div>
												<div class="col-md-12">
													<div class="page-content">
														<nav class="pagination" role="navigation">
															<a class="last-page" href="#">
																<i class="fa fa-angle-left"></i>
															</a>
															<span class="page-number">...</span>
															<a class="next-page" href="#">
																<i class="fa fa-angle-right"></i>
															</a>
														</nav>
													</div>
												</div>
											</div>
											<!-- 今日课堂 -->
											<div id="today-lesson-container">
												
											</div>
										</div>
										<div class="col-md-1"></div>
									</div>
								</div>
							</div>
							<div class="col-md-1"></div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	
	<%@include file="/common/footer.jsp" %>
</body>
<script>
var data = ${data};
$(document).ready(function() {
	if (data.status != "success") {
		alert(data.message);
		return;
	}
		
	initCourseList();
	initPage(data.data.pageNo,data.data.allpages);
	if(data.data.hasOwnProperty("assistant")){
		getLessonAssistant();
	}else {
		getLesson();
	}
});

var initCourseList = function() {
	var container = $("#container");
	var list = data.data.list;
	var s = "";
	for (var i = 0; i < list.length; i++) {
		s += ("<div class=\"col-md-4\">");
		s += ("<a href=\"<c:url value='/task/list?courseId="+list[i].id+"'/>\" title=\"" + list[i].name + "\"><div class=\"course-info\">");
		s += ("<div class=\"course-img\">");//临时加的课程图片
		s += ("<img src=\"<c:url value='/resource/picture/"+list[i].image+"' />\" alt=\"" + list[i].name +"\" />");
		s += ("</div>");//临时加的课程图片
		s += ("<div class=\"course-name\">" + list[i].name);
		s += ("</div>");
		s += ("<div class=\"course-class\">");
		s += ("<ul><li>课时：" + list[i].courseHour + "课时</li><li>学分："+ list[i].credit + "</li><li>课程总周次：" + list[i].sumWeeks + "周</li></ul>");
		s += ("</div></div>");
		s += ("</a></div>");
	}
	//alert(s);
	container.append(s);
}
var initPage = function(pageNo,allpages){
	
	var lastPageObj=$(".last-page");
	var nextPageObj=$(".next-page");
	var pageNumberObj=$(".page-number");
	var lastPage=pageNo-1;
	if(lastPage<=0){//设置disableed
		lastPage=1;
		lastPageObj.removeAttr("href");
	}else{
		lastPageObj.attr("href","<c:url value='/course/list?pageNo="+lastPage+"'/>");
	}
	var nextPage = pageNo+1;
	if(nextPage>allpages){
		nextPage=allpages;
		nextPageObj.removeAttr("href");
	}else{
		nextPageObj.attr("href","<c:url value='/course/list?pageNo="+nextPage+"'/>");
	}
	if(allpages==1){
		$(".page-content").hide();
	}else{
		$(".page-content").show();
		pageNumberObj.text("第"+pageNo+"页/共"+allpages+"页");
	}
	
}
	
var getLesson=function(){
	$.get("<c:url value='/lesson/ajaxTeacherCLesson'/>",function(data) {
		if(data.status=="success"){
			var lessons=data.data.list;
			initLesson(lessons);
		}
	});
}
	
var getLessonAssistant=function(){
	$.get("<c:url value='/lesson/ajaxAssistantCLesson'/>",function(data) {
		if(data.status=="success"){
			var lessons=data.data.list;
			initLesson(lessons);
		}
	});
}
	
var initLesson = function(lessons){
	var list=$("#today-lesson-container");
	if(lessons.length == 0) {
		list.html("<span style='text-align:center;'><h2 style=\"text-shadow: 4px 4px 8px #242a2f;font-size:1.8rem;\">今日无课！</h2></span>");
	} else {
		var s="";
		for(var i=0;i<lessons.length;i++){//
			s += ("<div class=\"col-md-4\">");
			s += ("<a href=\"<c:url value='/lessonTaskView/tlview?lessonId="+lessons[i].id+"'/>\" title=\"" + lessons[i].courseName + "\"><div class=\"course-info\">");
			s += ("<div class=\"course-img\">");//临时加的课程图片
			s += ("<img src=\"<c:url value='/resource/picture/"+lessons[i].image+"' />\" alt=\"" + lessons[i].courseName +"\" />");
			s += ("</div>");//临时加的课程图片
			s += ("<div class=\"course-name\">" + lessons[i].courseName);
			s += ("</div>");
			s += ("<div class=\"course-class\">");
			if(lessons[i].location == null){
				s += ("<ul title=\"上课时间:"+lessons[i].beginDate + "--" + lessons[i].endDate+"上课地点:(无)\"><li>上课时间:</li><li> " + lessons[i].beginDate + "--" + lessons[i].endDate + "</li><li>上课地点:(无)</li></ul>");
			}else{
				s += ("<ul title=\"上课时间:"+lessons[i].beginDate + "--" + lessons[i].endDate+"上课地点:"+lessons[i].location+"\"><li>上课时间:</li><li> " + lessons[i].beginDate + "--" + lessons[i].endDate + "</li><li>上课地点:" + lessons[i].location + "</li></ul>");
			}				
			s += ("</div></div>");
			s += ("</a></div>");
		}
		list.empty();
		list.append(s);
	}
}	

</script>
</html>